<template>
  <header class="header">
    <h1>todos</h1>
    <input @input="check" :disabled="list.length === 0" :checked="todoAll" id="toggle-all" class="toggle-all" type="checkbox" >
    <label for="toggle-all"></label>
    <input
      class="new-todo"
      placeholder="输入任务名称-回车确认"
      autofocus
      v-model.trim="taskname"
      @keydown.enter="add"
    />
  </header>
</template>

<script>
import { mapState , mapGetters , mapMutations } from 'vuex'
export default {
 
  data() {
    return {
      taskname: '',
      val:false
      
    }
  },
  methods: {
    add() {
      if (this.taskname.length === 0) return alert('请输入任务名称!')
      this.$store.commit('todoList/todoAdd', {taskname:this.taskname})
      this.taskname = ''
    },
    check(e) {
      console.log(e.target.checked);
      this.$store.commit('todoList/setAll', e.target.checked)
    }
  },
  computed: {
    ...mapState('todoList',['list']),
    ...mapGetters('todoList',['todoAll'])
  }
}
</script>